﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using SubSystem.Models;

namespace SubSystem.Helpers
{
    public static class HtmlArticleMenu
    {
        public static string ArticleMenu(this HtmlHelper html, IArticle article)
        {
            var result = string.Empty;
            
            result = AppendEditButton(html, article, result);

            result = AppendAddButton(html, result);

            return result;
        }

        private static string AppendAddButton(HtmlHelper html, string result)
        {
            if (html.ViewContext.HttpContext.User.Identity.Name == "agileguy")
            {
                result += string.Format("\n&nbsp;\n<a href=\"/Article/Add/{0}\" class=\"ArticleLink\">Add</a>",
                                        Guid.NewGuid());
            }
            return result;
        }

        private static string AppendEditButton(HtmlHelper html, IArticle article, string result)
        {
            if (html.ViewContext.HttpContext.User.Identity.Name == "agileguy")
            {
                result = string.Format("<a href=\"/Article/Edit/{0}\" class=\"ArticleLink\">Edit</a>", article.Id);
            }
            return result;
        }
    }
}
